Code Implementation

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main() {
    int rows, columns;

    // Prompt user for number of rows and columns
    cout << "Enter the number of rows: ";
    cin >> rows;
    cout << "Enter the number of columns: ";
    cin >> columns;

    // Create a 2D array to store the table data
    string tableData[rows][columns];

    // Get data cell by cell from the user
    cout << "Enter the data for the table:\n";
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < columns; j++) {
            cout << "Enter data for cell (" << i + 1 << ", " << j + 1 << "): ";
            cin >> tableData[i][j];
        }
    }

    // Generate HTML content
    string htmlContent = "<!DOCTYPE html>\n<html>\n<head>\n<title>Table</title>\n</head>\n<body>\n<table border=\"1\">\n";

    for (int i = 0; i < rows; i++) {
        htmlContent += "  <tr>\n";
        for (int j = 0; j < columns; j++) {
            htmlContent += "    <td>" + tableData[i][j] + "</td>\n";
        }
        htmlContent += "  </tr>\n";
    }

    htmlContent += "</table>\n</body>\n</html>";

    // Store the HTML page in a file
    ofstream outFile("table.html");
    if (outFile.is_open()) {
        outFile << htmlContent;
        outFile.close();
        cout << "HTML table has been generated and saved as 'table.html' in the current folder.\n";
    } else {
        cerr << "Error: Unable to create the HTML file.\n";
    }

    return 0;
}
Web hosting by Somee.com